package com.project.customview.calc;

import android.animation.ObjectAnimator;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.project.customview.R;
import com.project.customview.annotation.Inject;
import com.project.customview.annotation.InjectView;
import com.project.customview.annotation.OnClick;

public class CalcActivity extends AppCompatActivity implements View.OnClickListener {

    @InjectView(R.id.calc_image)
    ImageView calcImageView;
    @InjectView(R.id.btn1)
    Button btn1;
    @InjectView(R.id.btn2)
    Button btn2;
    @InjectView(R.id.btn3)
    Button btn3;
    @InjectView(R.id.btn4)
    Button btn4;
    @InjectView(R.id.btn5)
    Button btn5;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_calc);
        Inject.inject(this);
        btn1.setOnClickListener(this);
        btn2.setOnClickListener(this);
        btn3.setOnClickListener(this);
        btn4.setOnClickListener(this);
        btn5.setOnClickListener(this);

    }
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            //左右移动
            case R.id.btn1:
                ObjectAnimator animator1 = ObjectAnimator.ofFloat( calcImageView, "translationX",
                        0, 300, -100, 200, -50, 0);
                animator1.setDuration(2000);
                animator1.start();
                break;
            case R.id.btn2:
                Log.i("aaa","2222222222");
                ObjectAnimator animator2 = ObjectAnimator.ofFloat(calcImageView, "scaleY", 0f,
                        1.5f, 2f, 1.5f, 0f, 0.5f, 0.2f, 1f);
                animator2.setDuration(2000);
                calcImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                animator2.start();
                break;
            case R.id.btn3:
                Log.i("aaa","333333");
                //旋转
                ObjectAnimator animator3 = ObjectAnimator.ofFloat(calcImageView, "rotationY", 0,
                        180, 0, -180, 0);
                animator3.setDuration(3000);
                calcImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                animator3.start();
                break;
            case R.id.btn4:
                Log.i("aaa","44444");

                Path path = new Path();
                path.quadTo(800, 200, 800, 800);
                ObjectAnimator animator4 = ObjectAnimator.ofFloat(calcImageView, "x", "y", path);
                animator4.setDuration(4000);
                animator4.start();
                break;
            case R.id.btn5:
            ObjectAnimator animator5 = ObjectAnimator.ofArgb(calcImageView, "BackgroundColor",
                    0xffff00ff, 0xffffff00, 0xffff00ff);
            animator5.setDuration(4000);
            animator5.start();
            break;


        }

    }
}
